package cn.jfinal.interceptor;

import com.jfinal.aop.Interceptor;
import com.jfinal.aop.Invocation;
import com.jfinal.kit.JsonKit;
import org.apache.log4j.Logger;

import javax.servlet.http.HttpServletRequest;
import java.util.LinkedHashMap;
import java.util.Map;


/**
 * @packageName: cn.jfinal.interceptor
 * @name: RequestInterceptor
 * @description:
 * @author: 董定卓
 * @dateTime: 2018/8/23 10:08
 */
public class RequestInterceptor implements Interceptor {

    Logger logger = Logger.getLogger(RequestInterceptor.class);

    public void intercept(Invocation invocation) {
        HttpServletRequest request = invocation.getController().getRequest();

        Map<String, Object> actionMap = new LinkedHashMap<String, Object>();
        actionMap.put("url", request.getRequestURI());
        actionMap.put("param", JsonKit.toJson(request.getParameterMap()));
        logger.info(actionMap);

        invocation.invoke();
    }
}
